package com.example.intelligentattendancesystem.controller;

import com.example.intelligentattendancesystem.pojo.User;
import com.example.intelligentattendancesystem.pojo.Work;
import com.example.intelligentattendancesystem.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author
 * @version 1.0
 * @className WorkTableController
 * @since 1.0
 */
@RestController
@RequestMapping("smartAttendance/workTable")
public class WorkTableController {
    @Autowired
    WorkService workService;
    /**
     *设置时刻表（week为-1的就是时刻表）
     * @param works 时刻表中的时间段
     * @return
     */
    @RequestMapping("setTimeTable")
    public Boolean workTableSetTimeTable(@RequestBody List<Work> works){
        Boolean aBoolean = workService.setTimeTableService(works);
        return aBoolean;
    }

    /**
     * 获取所有的工作表（管理员）
     * @param userId
     * @return
     */
    @RequestMapping("getTable")
    public List<Work> getTable(int userId){
        List<Work> tableService = workService.getTableService(userId);
        return tableService;
    }

    /**
     * 获取工作表（用户）
     * @param userId
     * @return
     */
    @RequestMapping("getUserTable")
    public List<Work> getUserTable(int userId){
        List<Work> userTableService = workService.getUserTableService(userId);
        return userTableService;
    }

    /**
     * 获取时刻表格中的员工列表
     * @param startTime
     * @param endTime
     * @param week
     * @return
     */
    @RequestMapping("workerList")
    public List<User> getWorkerList(String startTime,String endTime,String week){
        List<User> workerListService = workService.getWorkerListService(startTime, endTime, week);
        return workerListService;
    }

    /**
     * 删除该时刻表格的员工
     * @param work
     * @return
     */
    @RequestMapping("workerDelete")
    public boolean workerDelete(Work work){
        boolean b = workService.workerDeleteService(work);
        return b;
    }

    /**
     * 获取该时刻表格未添加的员工
     * 该时刻表格不用获取，前端传的是时刻表格里已经有的用户
     * @param userIds
     * @return
     */
    @RequestMapping("getNoAddUserList")
    public List<User> getNoAddUserList(@RequestBody List<Integer> userIds){
        List<User> noAddUserListService = workService.getNoAddUserListService(userIds);
        return noAddUserListService;
    }

    /**
     * 添加work表
     * @param work
     * @return
     */
    @RequestMapping("workerInsert")
    public boolean workerInsert(Work work){
        boolean b = workService.workerInsertService(work);
        return b;
    }

    /**
     * 修改工作表
     * 该工作表的员工的时间会被修改
     * @param works
     * @return
     */
    @RequestMapping("updateTable")
    public int modifyTimeTable(@RequestBody  List<Work> works){
        return workService.modifyTimeTable(works);
    }
    @RequestMapping("deleteTimeTable")
    public int deleteTimeTable(Work work){
        return workService.deleteTimeTable(work);
    }

}
